package io.renren.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.exception.RRException;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.app.dao.BsBorrviolationDao;
import io.renren.modules.app.entity.BsBorrviolationEntity;
import io.renren.modules.app.service.BsBorrviolationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;



@Service("bsBorrviolationService")
@Slf4j
public class BsBorrviolationServiceImpl extends ServiceImpl<BsBorrviolationDao, BsBorrviolationEntity> implements BsBorrviolationService {

    @Resource
    private BsBorrviolationDao bsBorrviolationDao ;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        LambdaQueryWrapper<BsBorrviolationEntity> queryWrapper = new LambdaQueryWrapper<>() ;
        if (params.get("violadescribe") != null && !params.get("violadescribe").equals("")){
            queryWrapper.like(BsBorrviolationEntity::getVioladescribe,params.get("violadescribe"));
        }

        IPage<BsBorrviolationEntity> page = this.page(
                new Query<BsBorrviolationEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void updateBsBorrviolationEntity(BsBorrviolationEntity bsBorrviolation) {
       try {
           //借阅信息id不允许修改
           BsBorrviolationEntity bsBorrviolationEntity = bsBorrviolationDao.selectById(bsBorrviolation.getId());
           if (!bsBorrviolationEntity.getViolainformid().equals(bsBorrviolation.getViolainformid())){
               throw new RRException("借阅信息ID不允许修改");
           }
           bsBorrviolationDao.updateById(bsBorrviolation);
       }catch (Exception e){
           log.info(e.getMessage());
           throw new RRException(e.getMessage());
       }
    }

}
